package com.nulldev.util.web.YouTubeExtractor.comments.testing;

import com.nulldev.util.JVM.Arguments;
import com.nulldev.util.JVM.JVM;
import com.nulldev.util.VariableAPI.ArrayUtils;
import com.nulldev.util.concurrency.threadIt.v4.emapi.ExecutorManager;
import com.nulldev.util.concurrency.threadIt.v4.emapi.uft.Executable;
import com.nulldev.util.data.Arrays.maps.FastMaps;
import com.nulldev.util.io.FastIO.FastIO;
import com.nulldev.util.web.YouTubeExtractor.YouTubeExtractor;
import com.nulldev.util.web.YouTubeExtractor.comments.YTComments;
import com.nulldev.util.web.YouTubeExtractor.comments.YTComments.YTCommentInitData;
import com.nulldev.util.web.YouTubeExtractor.comments.YTComments.YouTubeCommentResult;
import com.nulldev.util.web.YouTubeExtractor.extractors.IYouTubeExtractor;
import com.nulldev.util.web.YouTubeExtractor.extractors.IYouTubeExtractorConstants;
import com.nulldev.util.web.YouTubeExtractor.video.ExtractedVideo;

public class ExtractorBasedComments {

	public static void main(String[] args) throws Exception {
		Arguments.setup(new String[]
			{ "--YTComments.enableDesktop" });
		YouTubeExtractor.extractor.waitFor();
		final String VIDEO_ID = "92LTXSBVxoc";
		final IYouTubeExtractor ex = YouTubeExtractor.get("YouTubeExtractor.NFEE_rolling_release");
		final Executable<ExtractedVideo> f = ex.generateTask(FastMaps.fixedUniMap(new Object[][]
			{
					{ IYouTubeExtractorConstants.MAP_TYPE_VIDEO_ID, VIDEO_ID } }));
		ExecutorManager.get().asyncSubmit(f);
		JVM.println("result: " + f.waitTillCompletion());
		if (f.result().supportsLateExtraction()) {
			f.result().awaitCompletion();
			JVM.println("lateExtraction: COMPLETE");
		}
		if (f.result().hasCommentData()) {
			JVM.println("commentData: " + f.result().getCommentData());
			final YTCommentInitData id = f.result().getCommentData(); // YTCommentInitData.make(VIDEO_ID);
			JVM.println("id: " + id);
			final YouTubeCommentResult d = YTComments.getComments(id);
			JVM.println(d);
			ArrayUtils.printLln(d.getComments());
		} else
			throw new RuntimeException("Comment data misssing!");
		FastIO.get().flush();
		JVM.exit();
	}
}
